home *** CD-ROM | disk | FTP | other *** search
/ Reverse Code Engineering RCE CD +sandman 2000 / ReverseCodeEngineeringRceCdsandman2000.iso / RCE / Library / Manuels & Misc / Assembly / AOA.ZIP / CH16 / MATCHPRE.ASM < prev    next >
Encoding:
Assembly Source File  |  1994-07-09  |  838 b   |  44 lines

  1.  
  2. MatchPre    proc    far        ;Must be far!
  3.         push    bp
  4.         mov    bp, sp
  5.         push    ax
  6.         push    ds
  7.         push    si
  8.         push    di
  9.  
  10.         lds    si, 2[bp]    ;Get the return address.
  11. CmpLoop:    mov    al, ds:[si]    ;Get string to match.
  12.         cmp    al, 0        ;If at end of prefix,
  13.         je    Success        ; we succeed.
  14.         cmp    al, es:[di]    ;See if it matches prefix,
  15.         jne    Failure        ; if not, immediately fail.
  16.         inc    si
  17.         inc    di
  18.         jmp    CmpLoop
  19.  
  20. Success:    add    sp, 2        ;Don't restore di.
  21.         inc    si        ;Skip zero terminating byte.
  22.         mov    2[bp], si    ;Save as return address.
  23.         pop    si
  24.         pop    ds
  25.         pop    ax
  26.         pop    bp
  27.         stc            ;Return success.
  28.         ret
  29.  
  30. Failure:        inc    si        ;Need to skip to zero byte.
  31.         cmp    byte ptr ds:[si], 0
  32.         jne    Failure
  33.         inc    si
  34.         pop    di
  35.         mov    2[bp], si    ;Save as return address.
  36.         pop    si
  37.         pop    ds
  38.         pop    ax
  39.         pop    bp
  40.         clc            ;Return failure.
  41.         ret
  42. MatchPre    endp
  43.         end
  44.